/*
 * @Author: toString muzi_li0323@163.com
 * @Date: 2024-05-23 18:54:41
 * @LastEditors: toString muzi_li0323@163.com
 * @LastEditTime: 2024-05-23 22:13:39
 * @FilePath: /chain-link-api-front/src/views/store/user.js
 * @Description: 用户信息
 */
import { defineStore } from 'pinia'
import { computed, ref, unref } from "vue";
export const useUserStore = defineStore('user', {
  state:() => ({
    userInfo: {},
    token: '',
    locale: 'zh-TW',
    address:{}
  }),
  getters: {
    getUserInfo: (state) => state.userInfo,
    getToken: (state) => state.token,
    getLocale: (state) => state.locale,
    getAddress: (state) => state.address,
  },
  actions: {
    setAddress(address) {
      this.address = address
    },
    setUserInfo(info) {
      this.userInfo = info
    },
    setToken(tk) {
      this.token = tk
    },
    setLocale(value){
      this.locale = value
    },
    clear() {
      this.userInfo = {}
      this.token = ''
      this.address = {}
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        storage: sessionStorage,//存储方式
        // paths: ["userInfo","token"]//存储属性
      }
    ]
  }
})